//Download by www.cctry.com
#include <memory>
#include <mutex>
struct some_resource {
    void do_something() {}  
};
std::shared_ptr<some_resource> resource_ptr;
std::mutex resource_mutex;
void foo() {
    std::unique_lock<std::mutex> lk(resource_mutex);
    if(!resource_ptr) {
        resource_ptr.reset(new some_resource); //initialization，初始化
    }
    lk.unlock();
    resource_ptr->do_something();
}
int main() {
    foo();
}